package actions;

import gui.UserPanel;
import information.Job;
import information.User;
import information.Usertype;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Set;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * An action that will display a job in another panel. 
 * 
 * @author Natalie
 *
 */
@SuppressWarnings("serial")
public class ViewJobsAction extends AbstractAction {
	
	/**
	 * The job that will be displayed. 
	 */
	private Job myJob;
	
	private User myUser;
	
	public ViewJobsAction(final Job theJob, final String theTitle, final User theUser) {
		super(theTitle);
		myJob = theJob;
		myUser = theUser;
	}
	
	/**
	 * When an action event occurs this will create a new frame with the 
	 * Jobs information displayed. 
	 */
	@Override
	public void actionPerformed(ActionEvent theEvent) {
		JFrame frame = new JFrame();
		frame.setPreferredSize(new Dimension(500, 500));
		frame.setLayout(new BorderLayout());
		UserPanel panel = new UserPanel(null);
		Set<Job> jobs = new HashSet<Job>();
		jobs.add(myJob);
		panel.displayJobs(jobs);
		frame.add(panel, BorderLayout.CENTER);
		//Only a staff member is allowed to view the volunteers signed up for the job. 
		if (myUser.getUsertype() == Usertype.STAFFMEMBER)	frame.add(new JButton(new ViewVolunteersAction(myJob)), BorderLayout.SOUTH);
		frame.pack();
		frame.setVisible(true);

	}

}
